from selenium.webdriver.common.by import By
from pages.base_page import Page


class CannedMessagesPage(Page):
    ele_title = (By.XPATH, u"//h3[text()='Canned Messages for Campaign']")
    ele_error = (By.XPATH, u'//div[@role="alert"]')

    ele_feature_switch = (By.XPATH, u"//span[@data-tag='featureSwitch']")
    ele_is_enable_feature_switch = (By.XPATH, u"//span[@data-tag='featureSwitch']")

    ele_unselected = (By.XPATH, u"//span[text()='Unselected Categories']")
    ele_selected = (By.XPATH, u"//span[text()='Selected Categories']")

    ele_canned_messages_save_button = (By.XPATH, u"(//button[@data-tag='formButton'])[1]")

    # 如果没有CannedMessages功能，则检查图片和unlock button
    ele_img = (By.XPATH, u'//img[@alt="Canned Messages Introduction"]')
    ele_unlock_this_feature = (By.XPATH, u'//span[text()="Unlock This Feature"]')


    def __init__(self, driver, url, site_id):
        Page.__init__(self, driver, url)
        self.site_id = site_id
        self.url = url

    # this method should be called first
    def is_enable_feature_switch(self):
        fs = self.find_element(*self.ele_is_enable_feature_switch)
        if fs.text == 'OFF':
            self.click(self.ele_feature_switch)
        else:
            pass

    def check_canned_messages_page_when_has_canned_messages_feature(self):
        self.find_element(*self.ele_title).is_enabled()
        self.find_element(*self.ele_is_enable_feature_switch).is_enabled()
        self.find_element(*self.ele_selected).is_enabled()

    def check_save_button_when_has_canned_messages_feature(self):
        self.click(self.ele_canned_messages_save_button)

    def check_canned_messages_page_when_no_canned_messages_feature(self):
        # self.find_element(*self.ele_title).is_enabled()
        self.find_element(*self.ele_img).is_enabled()
        self.find_element(*self.ele_unlock_this_feature).is_enabled()
